<?php
/**
 * Receipt.php
 *
 * @copyright   2023 thingsworld.com.cn - All Rights Reserved
 * @link        http://thingsworld.com.cn/
 * @author      stiffer.chen <chenl@thingsworld.com.cn>
 * @created     2023-02-18 16:47:56
 * @modified    2023-02-18 16:47:56
 *
 */

namespace App\Models\WorkOrder;

use App\Models\BaseModel;
use App\Models\WorkOrder\Receipt\Bom;
use App\Models\WorkOrder\Receipt\Service;
use App\Services\ImageServ;

class Receipt extends BaseModel
{
    protected $table = 'work_order_receipt';
    protected $fillable = [
        'work_order_id',
        'reason',
        'process_type',
        'description',
        'signature',
        'satisfaction',
        'attitude',
        'efficiency'
    ];

    protected $appends = [
        'signature_url'
    ];

    public function getSignatureUrlAttribute()
    {
        $signature = $this->signature;
        $url = (new ImageServ($signature))->getUrl();
        return $url;
    }

    public function images()
    {
        return $this->hasMany(\App\Models\WorkOrder\Receipt\Image::class,  'work_order_receipt_id', 'id');
    }

    public function boms()
    {
        return $this->hasMany(Bom::class, 'work_order_receipt_id', 'id');
    }

    public function services()
    {
        return $this->hasMany(Service::class, 'work_order_receipt_id', 'id');
    }
}